<?php

 function getPagingLink($sql_1, $itemPerPage,$link,$sort='')

  {

	$result        = mysql_query($sql_1." ".$cond);

	$pagingLink    = '';

	$totalResults  = mysql_num_rows($result);

  $totalPages    = ceil($totalResults / $itemPerPage);
 //$cat_id=$cid;


	// how many link pages to show

	$numLinks      = 1;



		

	// create the paging links only if we have more than one page of results

	if ($totalPages > 1) {

 	

		$self = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];

		



		if (isset($_GET['page']) && (int)$_GET['page'] > 0) {

			$pageNumber = (int)$_GET['page'];

		} else {

			$pageNumber = 1;

		}

		

		// print 'previous' link only if we're not

		// on page one

		if ($pageNumber > 1) {

			$page = $pageNumber - 1;



			if ($page > 1) {

				$prev = "<td>&nbsp;<a href=\"$self?$link&page=$page$sort\" class=h1 title=\"Previous\"><img style='border: 0px none;' src='../images/arrow_left.png' align='absmiddle' /></a>&nbsp;</td>";

			} else {

			

				$prev = "<td>&nbsp;<a href=\"$self?&$link$sort\" class=h1 title=\"Previous\"><img style='border: 0px none;' src='../images/arrow_left.png' align='absmiddle' /></a>&nbsp;</td>";

			}	

				

			$first = " <td>&nbsp;<a href=\"$self?&$link$sort\" class=h1 title=\"First\">&lsaquo;&lsaquo;</a>&nbsp;</td> ";

		} else {

		

			$prev  = ''; // we're on page one, don't show 'previous' link

			$first = ''; // nor 'first page' link

		}

	

		// print 'next' link only if we're not

		// on the last page

		if ($pageNumber < $totalPages) {

		//echo $itemPerPage;

			$page = $pageNumber + 1;

			$next = "<td>&nbsp; <a href=\"$self?$link&page=$page$sort\" class=h1 title=\"Next\"><img style='border: 0px none;' src='../images/arrow_right.png' align='absmiddle' /></a>&nbsp;</td> ";

			$last = "<td>&nbsp; <a href=\"$self?$link&page=$totalPages$sort\" class=h1 title=\"Last\">&rsaquo;&rsaquo;</a>&nbsp;</td> ";

		} else {

			$next = ''; // we're on the last page, don't show 'next' link

			$last = ''; // nor 'last page' link

		}



		$start = $pageNumber - ($pageNumber % $numLinks) + 1;

		$start -= 1;

		$end   = $start + $numLinks - 1;		

			

		$end   = min($totalPages, $end);

		

		$pagingLink = array();

		for($page = $start; $page <= $end; $page++)	{

		if($page!=0){

			if ($page == $pageNumber) {

				$pagingLink[] = "<td>&nbsp;<span class=fntv><b>Page $page</b></span>&nbsp;</td>";   // no need to create a link to current page

			} else {

				if ($page == 1) {

					$pagingLink[] = " <td>&nbsp;<a href=\"$self?$link$sort\" class=h1>$page</a>&nbsp;</td> ";

				} else {	

					$pagingLink[] = " <td>&nbsp;<a href=\"$self?$link&page=$page$sort\" class=h1>$page</a>&nbsp;</td> ";

				}	

			}

		}

		}

		

		$pagingLink = implode('', $pagingLink);

		

		// return the page navigation link

		$pagingLink="<table align=\"center\" border=0 style=\"border-collapse:collapse;\" bgcolor=\"white\" bordercolor=\"#717171\" height=\"10\"><tr>".
		$prev.$pagingLink.$next."</tr></table>";
		//$first.$prev.$pagingLink.$next.$last."</tr></table>";

		//$pagingLink = $first . $prev . "<span class=fntv>".$pagingLink."</span>". $next . $last;

	}

	

	return $pagingLink;

 }

 

function getPagingQuery($sql_1 , $itemPerPage)

{
	
	if (isset($_GET['page']) && (int)$_GET['page'] > 0) {

		$page = (int)$_GET['page'];

	} else {

		$page = 1;

	}

	

	// start fetching from this row number

	$offset = ($page - 1) * $itemPerPage;

	
		
	return $sql_1 . " LIMIT $offset, $itemPerPage";

}  



?>

